import { ref, computed, reactive, onMounted } from "vue";
import { defineStore } from "pinia";
import { get, post } from "../util/request.js";
export const useCounterStore = defineStore(
  "counter",
  () => {
    const info = ref({});
    const products = reactive([
      { id: 1, name: "Product 1", price: 100 },
      { id: 2, name: "Product 2", price: 200 },
      { id: 3, name: "Product 3", price: 300 },
    ]);
    const list = ref([]);
    const dynamicColumns = ref([]);
    const getList = async () => {
      await get("/message/getuser").then((res) => {
        list.value = res.data.data;
        if (res.data.data.length > 0) {
          const firstItem = res.data.data[0];
          dynamicColumns.value = Object.keys(firstItem).map((key) => ({
            label: key.charAt(0).toUpperCase() + key.slice(1), // 首字母大写
            sortKey: key,
          }));
        }
      });
      await getsalodName();
    };
    const salodName = ref("");
    const salodList=ref([])
    const getsalodName = async () => {
      let {
        data: { data, code },
      } = await get("/shopfront/getsalon");
      if (code == 200) {
        salodList.value = data
      }
      salodList.value.forEach((item) => {
        console.log(info.value,'11223');
        
        if (item._id == info.value.salonId) {
          salodName.value = item.name;
        }
      })
      console.log(salodName.value,'333333');

    };
    onMounted(() => {
      getList();
    });
    return {
      products,
      list,
      dynamicColumns,
      getList,
      info,
      salodName,
    };
  },
  {
    persist: {
      enabled: true, // 开启数据持久化
    },
  }
);
